var _page = $('.page')

var thisload1 = bottlecms.load({
    elem: $('.infinite-chat1'),
    scroll: $('.infinite-scroll1'),
    done: function (page, next) {
        var src = this.elem.attr("pages-src");
        bottlecms.get(src, {
            page: page
        }, function (data) {
            var lis = [];
            for (var o in data.list) {
                lis.push(chat_template(data.list[o]))
            }
            next(lis.join(''), lis.length);
        })
    }
})

var thisload2 = bottlecms.load({
    elem: $('.infinite-chat2'),
    scroll: $('.infinite-scroll2'),
    done: function (page, next) {
        var src = this.elem.attr("pages-src");
        bottlecms.get(src, {
            page: page
        }, function (data) {
            var lis = [];
            for (var o in data.list) {
                lis.push(friend_template(data.list[o]))
            }
            next(lis.join(''), lis.length);
        })
    }
})

var tabload = function () {
    setTimeout(function () {
        if ($('.bcui-tab .bcui-tab-content .item.active .infinite-chat1').length > 0) {
            thisload1.init();
        } else if ($('.bcui-tab .bcui-tab-content .item.active .infinite-chat2').length > 0) {
            thisload2.init();
        }
    }, 100)
}

$(_page).on('click', '.bcui-tab .bcui-tab-title .item', function (event) {
    tabload();
});
tabload();

bottlecms.long_press(_page, '.js-chatlist .item', function (_this) {
    let user_id = $(_this).attr('data-uid');
    bottlecms.actions([
        [{
            text: '查看资料',
            onClick: function (modal, e) {
                bottlecms.goto('/m/single/info/' + user_id);
            }
        }, {
            text: '删除聊天记录',
            onClick: function (modal, e) {
                delete_chat_fun(user_id, function () {
                    $(_this).remove();
                });
            }
        }],
        [{
            text: '取消',
            bg: 'danger'
        }]
    ]);
}, function (_this) {
    $(_this).find('.unreadNum').remove();
    bottlecms.goto('/m/chat/' + $(_this).attr('data-uid'));
});

bottlecms.long_press(_page, '.friendlist .bcui-infinite-list .item', function (_this) {
    let user_id = $(_this).attr('data-uid');
    bottlecms.actions([
        [{
            text: '查看资料',
            onClick: function (modal, e) {
                bottlecms.goto('/m/single/info/' + user_id);
            }
        }, {
            text: '删除',
            onClick: function (modal, e) {
                delete_friend_fun(user_id, function () {
                    $(_this).remove();
                });
            }
        }],
        [{
            text: '取消',
            bg: 'danger'
        }]
    ]);
}, function (_this) {
    bottlecms.goto('/m/chat/' + $(_this).attr('data-uid'));
});